<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="common/header.jsp" %>
<div class="clearfix"></div>
<div class="row">

    <div class="col-md-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>
                    APP 审核列表 <i class="fa fa-user"></i><small>${userNames}
                    - 您可以通过搜索或者其他的筛选项对APP的信息进行审核操作。^_^</small>
                </h2>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <form method="post" action="${pageContext.request.contextPath}/app/applist" id="qf">
                    <input type="hidden" name="pageIndex" value="1"/>
                    <ul>
                        <li>
                            <div class="form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12">软件名称</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input name="softwareName" type="text" class="form-control col-md-7 col-xs-12"
                                           value="${appInfo.softwareName}">
                                    <input type="hidden" name="pageNum" value="${page.pageNum}" id="pageNum">
                                    <input type="hidden" name="pageSize" value="${page.pageSize}" id="pageSize">
                                </div>
                            </div>
                        </li>

                        <li>
                            <div class="form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12">所属平台</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <select name="flatFormId" class="form-control">
                                        <c:if test="${flatFormList != null }">
                                            <option value="">--请选择--</option>
                                            <c:forEach var="dataDictionary" items="${flatFormList}">
                                                <option
                                                        <c:if test="${dataDictionary.valueId == appInfo.flatFormId}">selected="selected"</c:if>
                                                        value="${dataDictionary.valueId}">${dataDictionary.valueName}</option>
                                            </c:forEach>
                                        </c:if>
                                    </select>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12">一级分类</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <select id="queryCategoryLevel1" name="categoryLevel1" class="form-control">
                                        <c:if test="${categoryLevel1List != null }">
                                            <option value="">--请选择--</option>
                                            <c:forEach var="appCategory" items="${categoryLevel1List}">
                                                <option
                                                        <c:if test="${appCategory.id == queryCategoryLevel1 }">selected="selected"</c:if>
                                                        value="${appCategory.id}">${appCategory.categoryName}</option>
                                            </c:forEach>
                                        </c:if>
                                    </select>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12">二级分类</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input type="hidden" name="categorylevel2list" id="categorylevel2list"/>
                                    <select name="categoryLevel2" id="queryCategoryLevel2" class="form-control">
                                        <c:if test="${categoryLevel2List != null }">
                                            <option value="">--请选择--</option>
                                            <c:forEach var="appCategory" items="${categoryLevel2List}">
                                                <option
                                                        <c:if test="${appCategory.id == queryCategoryLevel2 }">selected="selected"</c:if>
                                                        value="${appCategory.id}">${appCategory.categoryName}</option>
                                            </c:forEach>
                                        </c:if>
                                    </select>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12">三级分类</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <select name="categoryLevel3" id="queryCategoryLevel3" class="form-control">
                                        <c:if test="${categoryLevel3List != null }">
                                            <option value="">--请选择--</option>
                                            <c:forEach var="appCategory" items="${categoryLevel3List}">
                                                <option
                                                        <c:if test="${appCategory.id ==queryCategoryLevel3 }">selected="selected"</c:if>
                                                        value="${appCategory.id}">${appCategory.categoryName}</option>
                                            </c:forEach>
                                        </c:if>
                                    </select>
                                </div>
                            </div>
                        </li>
                        <li>
                            <button type="submit" class="btn btn-primary"> 查 &nbsp;&nbsp;&nbsp;&nbsp;询</button>
                        </li>
                    </ul>
                </form>
            </div>
        </div>
    </div>
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_content">
                <p class="text-muted font-13 m-b-30"></p>
                <div id="datatable-responsive_wrapper"
                     class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                    <div class="row">
                        <div class="col-sm-12">
                            <table id="datatable-responsive"
                                   class="table table-striped table-bordered dt-responsive nowrap dataTable no-footer dtr-inline collapsed"
                                   cellspacing="0" width="100%" role="grid" aria-describedby="datatable-responsive_info"
                                   style="width: 100%;">
                                <thead>
                                <tr role="row">
                                    <th class="sorting_asc" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 70px;" aria-label="First name: activate to sort column descending"
                                        aria-sort="ascending">软件名称
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 10px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        APK名称
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 90px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        软件大小(单位:M)
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 50px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        所属平台
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 170px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        所属分类(一级分类、二级分类、三级分类)
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 30px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        状态
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 30px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        下载次数
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 64px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        最新版本号
                                    </th>
                                    <th class="sorting" tabindex="0"
                                        aria-controls="datatable-responsive" rowspan="1" colspan="1"
                                        style="width: 30px;"
                                        aria-label="Last name: activate to sort column ascending">
                                        操作
                                    </th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach var="appInfo" items="${page.list}" varStatus="status">
                                    <tr role="row" class="odd">
                                        <td tabindex="0" class="sorting_1">${appInfo.softwareName}</td>
                                        <td>${appInfo.APKName }</td>
                                        <td>${appInfo.softwareSize }</td>
                                        <td>${appInfo.flatformName }</td>
                                        <td>${appInfo.categoryLevel1Name } -> ${appInfo.categoryLevel2Name }
                                            -> ${appInfo.categoryLevel3Name }</td>
                                        <td>${appInfo.statusName }</td>
                                        <td>${appInfo.downloads }</td>
                                        <td>${appInfo.versionNo }</td>
                                        <td>
                                            <button type="button" class="btn btn-default checkApp"
                                                    appinfoid="${appInfo.id }" versionid="${appInfo.versionId }"
                                                    status="${appInfo.status }"
                                                    statusname="${appInfo.statusName }"
                                                    data-toggle="tooltip" data-placement="top" title=""
                                                    data-original-title="查看并审核APP">审核
                                            </button>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-5">
                            <div class="dataTables_info" id="datatable-responsive_info"
                                 role="status" aria-live="polite">共${page.total}条记录
                                ${page.pageNum }/${page.pages }页
                            </div>
                        </div>
                        <div class="col-sm-7">
                            <div class="dataTables_paginate paging_simple_numbers"
                                 id="datatable-responsive_paginate">
                                <ul class="pagination">
                                    <li class="paginate_button previous" id="first">
                                        <a href="javascript:void(0);" style="z-index: 0;"
                                           aria-controls="datatable-responsive" data-dt-idx="0"
                                           tabindex="0">
                                            <span aria-hidden="true">首页</span></a>
                                    </li>
                                    <li class="paginate_button " id="prev">
                                        <a style="z-index: 0;" href="javascript:void(0);" aria-label="Previous"
                                           aria-controls="datatable-responsive"
                                           data-dt-idx="1"
                                           tabindex="0"><span aria-hidden="true">上一页</span></a>
                                    </li>

                                    <c:forEach items="${page.navigatepageNums}" var="i">
                                        <li name="pageNum"
                                            <c:if test="${i==page.pageNum}">class="active" </c:if>><a
                                                href="javascript:void(0);" style="z-index: 0;">${i}</a></li>
                                    </c:forEach>

                                    <li class="paginate_button" id="next"><a
                                            href="javascript:void(0);" aria-label="Next"
                                            aria-controls="datatable-responsive" data-dt-idx="1"
                                            tabindex="0" style="z-index: 0;"><span aria-hidden="true">下一页</span></a>
                                    </li>
                                    <li class="paginate_button next" id="footing"><a
                                            href="javascript:void(0);"
                                            aria-controls="datatable-responsive" data-dt-idx="7"
                                            tabindex="0" style="z-index: 0;"><span aria-hidden="true">最后一页</span></a>
                                    </li>
                                </ul>
                                <%--                                <div>--%>
                                <%--                                    每页行数 <select id="setRows">--%>
                                <%--                                    <option value="3" <c:if test="${5==appInfoList.pageSize}"> selected</c:if>>3--%>
                                <%--                                    </option>--%>
                                <%--                                    <option value="5" <c:if test="${5==appInfoList.pageSize}"> selected</c:if>>5--%>
                                <%--                                    </option>--%>
                                <%--                                    <option value="10" <c:if test="${5==appInfoList.pageSize}"> selected</c:if>>10--%>
                                <%--                                    </option>--%>
                                <%--                                </select>--%>
                                <%--                                </div>--%>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <%@include file="common/footer.jsp" %>
    <%--<script src="${pageContext.request.contextPath }/statics/localjs/rollpage.js">--%>
    <script>
        function page_nav(frm, num) {
            frm.pageIndex.value = num;
            frm.submit();
        }
    </script>
    <%--<script src="${pageContext.request.contextPath }/statics/localjs/applist.js"></script>--%>

    <script>
        $("#queryCategoryLevel1").change(function () {
            var queryCategoryLevel1 = $("#queryCategoryLevel1").val();
            if (queryCategoryLevel1 != '' && queryCategoryLevel1 != null) {
                $.ajax({
                    type: "GET",//请求类型
                    url: "categorylevellist.json",//请求的url
                    data: {pid: queryCategoryLevel1},//请求参数
                    contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    dataType: "json",//ajax接口（请求url）返回的数据类型
                    success: function (data) {//data：返回数据（json对象）
                        $("#queryCategoryLevel2").html("");
                        var options = "<option value=\"\">--请选择--</option>";
                        for (var i = 0; i < data.length; i++) {

                            options += "<option value=\"" + data[i].id + "\">" + data[i].categoryName + "</option>";
                        }
                        $("#queryCategoryLevel2").html(options);
                    },
                    error: function (data) {//当访问时候，404，500 等非200的错误状态码
                        alert("加载二级分类失败！");
                    }
                });
            } else {
                $("#queryCategoryLevel2").html("");
                var options = "<option value=\"\">--请选择--</option>";
                $("#queryCategoryLevel2").html(options);
            }
            $("#queryCategoryLevel3").html("");
            var options = "<option value=\"\">--请选择--</option>";
            $("#queryCategoryLevel3").html(options);
        });

        $("#queryCategoryLevel2").change(function () {
            var queryCategoryLevel2 = $("#queryCategoryLevel2").val();
            if (queryCategoryLevel2 != '' && queryCategoryLevel2 != null) {
                $.ajax({
                    type: "GET",//请求类型
                    url: "categorylevellist.json",//请求的url
                    data: {pid: queryCategoryLevel2},//请求参数
                    contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    dataType: "json",//ajax接口（请求url）返回的数据类型
                    success: function (data) {//data：返回数据（json对象）
                        $("#queryCategoryLevel3").html("");
                        var options = "<option value=\"\">--请选择--</option>";
                        for (var i = 0; i < data.length; i++) {
                            //alert(data[i].id);
                            //alert(data[i].categoryName);
                            options += "<option value=\"" + data[i].id + "\">" + data[i].categoryName + "</option>";
                        }
                        $("#queryCategoryLevel3").html(options);
                    },
                    error: function (data) {//当访问时候，404，500 等非200的错误状态码
                        alert("加载三级分类失败！");
                    }
                });
            } else {
                $("#queryCategoryLevel3").html("");
                var options = "<option value=\"\">--请选择--</option>";
                $("#queryCategoryLevel3").html(options);
            }
        });

        $(".checkApp").on("click", function () {
            var obj = $(this);
            var status = obj.attr("status");
            var vid = obj.attr("versionid");
            if (status == "1" && vid != "" && vid != null) {//待审核状态下才可以进行审核操作
                window.location.href = "/app/check/" + obj.attr("appinfoid") + "/" + obj.attr("versionid");
            } else if (vid != "" || vid != null) {
                alert("该APP应用没有上传最新版本,不能进行审核操作！");
            } else if (status != "1") {
                alert("该APP应用的状态为：【" + obj.attr("statusname") + "】,不能进行审核操作！");
            }
        });
    </script>


    <script>
        //1、初始化变量
        var pageNum =${page.pageNum};//当前页
        var pages =${page.pages};//总页数
        var hasPreviousPage =${page.hasPreviousPage};//上一页
        var hasNextPage =${page.hasNextPage};//下一页

        console.log("当前页", pageNum, ",总页数", pages, "，上一页", hasPreviousPage, "，下一页", hasNextPage);

        //2、判断按钮状态
        if (!hasPreviousPage) {
            $("#prev").addClass('disabled');
            $("#first").addClass('disabled');
        }

        if (!hasNextPage) {
            $("#next").addClass('disabled');
            $("#footing").addClass('disabled');
        }


        //3、按钮事件监听
        //首页
        $("#first").click(function () {
            if (!$("#first").hasClass('disabled')) {//判断样式
                $("#pageNum").val(1);//隐藏参数当前页数
                $("#qf").submit();//查询条件提交id
            }
        })

        //上一页
        $("#prev").click(function () {
            if (!$("#prev").hasClass('disabled')) {//判断样式
                $("#pageNum").val(pageNum - 1);//隐藏参数当前页数
                $("#qf").submit();//查询条件提交id
            }
        })

        //下一页
        $("#next").click(function () {
            if (!$("#next").hasClass('disabled')) {//判断样式
                $("#pageNum").val(pageNum + 1);//隐藏参数当前页数
                $("#qf").submit();//查询条件提交id
            }
        })

        //页尾
        $("#footing").click(function () {
            if (!$("#footing").hasClass('disabled')) {//判断样式
                $("#pageNum").val(pages);//隐藏参数当前页数
                $("#qf").submit();//查询条件提交id
            }
        })

        //点击页码
        $("li[name='pageNum']").click(function () {
            if (!$(this).hasClass("active")) {
                $("#pageNum").val($(this).children("a").html());
                $("#qf").submit();
            }
        })

        // //每页行数
        // $("#setRows").change(function () {
        //     $("#pageSize").val($(this).val());
        //     $("#pageNum").val(1);
        //     $("#df").submit();
        // })


        //4、每页行数改变事件监听
        //5、点击页码事件监听


    </script>
